package test.mt;

import java.util.Scanner;

/**
 * @Description
 * @Author Firenut
 * @Date 2023-08-19 19:54
 */
public class T2 {
    static long max = 0;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] nums = new long[n];
        // 有n个数,n-1种运算结果
        long sum = 0;
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextLong();
            sum += nums[i];
        }
        for (int i = 0; i < n - 1; i++) {
            max = Math.max(max, sum - nums[i] - nums[i + 1] + nums[i] * nums[i + 1]);
        }
        System.out.println(max);
    }
}
